const { name } = require('./package.json');
const my_name  = require('./package.json').name

module.exports = {
  webpack: function override(config, env) {
    config.entry = config.entry.filter(
      (e) => !e.includes('webpackHotDevClient')
    );

   if(process.env.NODE_ENV === "production"){
	  const path = require('path');
	  const paths = require('react-scripts/config/paths');
	    
	   //修改配置里的appBuild目录，React项目在进行build的时候，都是根据这里配置的目录做的操作,必须要修改，不然打包会失败。
	    paths.appBuild = path.join(path.dirname(paths.appBuild), `../dist/subapp/${my_name}`);
	    //这行代码就是实现我们目的的根源了，修改项目打包地址。
	   config.output.path = path.join(path.dirname(config.output.path), `../dist/subapp/${my_name}`);
   }
	config.output.library = `${name}-[name]`;
    config.output.libraryTarget = 'umd';
    config.output.jsonpFunction = `webpackJsonp_${name}`;
    return config;
  },
  devServer: (configFunction) => {
    return function (proxy, allowedHost) {
      const config = configFunction(proxy, allowedHost);
      config.open = false;
      config.hot = false;
      config.headers = {
        'Access-Control-Allow-Origin': '*',
      };
      // Return your customised Webpack Development Server config.
      return config;
    };
  },
};
